package com.baibei.ebec.user.register;

import android.text.TextWatcher;
import android.view.View;
import android.widget.TextView;

/**
 * 文本相关扩展类
 * Created by ChenRui on 2017/8/2 0002 16:20.
 */
public final class TextViewCompat {

    public static void registerFormListener(final TextWatcher watcher, TextView... views) {
        for (TextView view : views) {
            view.addTextChangedListener(watcher);
            view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View view, boolean hasFoucs) {
                    if (!hasFoucs) {
                        watcher.onTextChanged(((TextView) view).getText(), 0, 0, 0);
                    }
                }
            });
        }
    }

    public static void unregisterFormListener(final TextWatcher watcher, TextView... views) {
        for (TextView view : views) {
            view.removeTextChangedListener(watcher);
            view.setOnFocusChangeListener(null);
        }
    }
}
